package day01;


import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;

public class DatagramSocketServer01 {
    public static void main(String[] args) throws IOException {
        //创建指定端口
        DatagramSocket server = new DatagramSocket(8090);
        byte[] buff = new byte[1024];
        DatagramPacket packet = new DatagramPacket(buff,0,buff.length);
        server.receive(packet);
        String data = new String(packet.getData(),0, packet.getLength());
        String clientIp = packet.getAddress().getHostAddress();
        String clientName = packet.getAddress().getHostName();
        int clientPort = packet.getPort();
        System.out.println("接收到来自:"+clientIp+" 主机名是"+clientName+"发来数据:["+data+"],对方端口号是"+clientPort);
    }
}
